Page({
  data: {},

  // ---------------生命周期钩子函数-begin----------------
  onLoad({ point, building }) {
    this.fake(point, building)
  },
  // ---------------生命周期钩子函数-end------------------

  // ---------------自定义函数-begin-----------------------
  // 1. 造假数据
  fake(point, building) {
    // 限定范围: 一次产生多少个房间号
    const size = Math.floor(Math.random() * 5) + 4
    const rooms = []
    for (let i = 0; i < size; i++) {
      // 产生随机楼层(1-20)
      const floor = Math.floor(Math.random() * 20) + 1
      // 产生随机的房间号(1-4)
      const No = Math.floor(Math.random() * 4) + 1
      // 形成房间号
      const room = [floor, '0', No].join('')
      // 判断是否有相同房间号
      if (rooms.includes(room)) continue
      // 把房间号放入数组
      rooms.push(room)
    }
    this.setData({ rooms, point, building })
  },

  // 2. 跳转到添加房屋页面
  goForm(ev) {
    const { point, building } = this.data
    // console.log(point, building, ev.mark.room)
    wx.navigateTo({
      url: `/house_pkg/pages/form/index?point=${point}&building=${building}&room=${ev.mark.room}`,
    })
  },
  // ---------------自定义函数-end-------------------------
})
